{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "5d1fcd0c",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: requests-html in c:\\users\\asus\\anaconda3\\lib\\site-packages (0.10.0)\n",
      "Requirement already satisfied: requests in c:\\users\\asus\\anaconda3\\lib\\site-packages (from requests-html) (2.31.0)\n",
      "Requirement already satisfied: pyquery in c:\\users\\asus\\anaconda3\\lib\\site-packages (from requests-html) (2.0.0)\n",
      "Requirement already satisfied: fake-useragent in c:\\users\\asus\\anaconda3\\lib\\site-packages (from requests-html) (1.2.1)\n",
      "Requirement already satisfied: parse in c:\\users\\asus\\anaconda3\\lib\\site-packages (from requests-html) (1.19.1)\n",
      "Requirement already satisfied: bs4 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from requests-html) (0.0.1)\n",
      "Requirement already satisfied: w3lib in c:\\users\\asus\\anaconda3\\lib\\site-packages (from requests-html) (1.21.0)\n",
      "Requirement already satisfied: pyppeteer>=0.0.14 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from requests-html) (1.0.2)\n",
      "Requirement already satisfied: appdirs<2.0.0,>=1.4.3 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from pyppeteer>=0.0.14->requests-html) (1.4.4)\n",
      "Requirement already satisfied: certifi>=2021 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from pyppeteer>=0.0.14->requests-html) (2023.7.22)\n",
      "Requirement already satisfied: importlib-metadata>=1.4 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from pyppeteer>=0.0.14->requests-html) (6.0.0)\n",
      "Requirement already satisfied: pyee<9.0.0,>=8.1.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from pyppeteer>=0.0.14->requests-html) (8.2.2)\n",
      "Requirement already satisfied: tqdm<5.0.0,>=4.42.1 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from pyppeteer>=0.0.14->requests-html) (4.65.0)\n",
      "Requirement already satisfied: urllib3<2.0.0,>=1.25.8 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from pyppeteer>=0.0.14->requests-html) (1.26.16)\n",
      "Requirement already satisfied: websockets<11.0,>=10.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from pyppeteer>=0.0.14->requests-html) (10.4)\n",
      "Requirement already satisfied: beautifulsoup4 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from bs4->requests-html) (4.12.2)\n",
      "Requirement already satisfied: lxml>=2.1 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from pyquery->requests-html) (4.9.2)\n",
      "Requirement already satisfied: cssselect>=1.2.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from pyquery->requests-html) (1.2.0)\n",
      "Requirement already satisfied: charset-normalizer<4,>=2 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from requests->requests-html) (2.0.4)\n",
      "Requirement already satisfied: idna<4,>=2.5 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from requests->requests-html) (3.4)\n",
      "Requirement already satisfied: six>=1.4.1 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from w3lib->requests-html) (1.16.0)\n",
      "Requirement already satisfied: zipp>=0.5 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from importlib-metadata>=1.4->pyppeteer>=0.0.14->requests-html) (3.11.0)\n",
      "Requirement already satisfied: colorama in c:\\users\\asus\\anaconda3\\lib\\site-packages (from tqdm<5.0.0,>=4.42.1->pyppeteer>=0.0.14->requests-html) (0.4.6)\n",
      "Requirement already satisfied: soupsieve>1.2 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from beautifulsoup4->bs4->requests-html) (2.4)\n"
     ]
    }
   ],
   "source": [
    "!pip install requests-html"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6b5e3a3b",
   "metadata": {},
   "source": [
    "# 第一个AJEX数据请求\n",
    ">1.数据源是从chrome浏览器xhr中查询到的\n",
    ">2.尝试使用浏览器中的requests header和payload\n",
    ">3.该数据基本描述：页面cardlist数据的数据源"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9ebd3733",
   "metadata": {},
   "outputs": [],
   "source": [
    "#请求数据准备\n",
    "# header\n",
    "import liepindata\n",
    "headers = liepindata.headers()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e3fa7d0f",
   "metadata": {},
   "source": [
    "# 备注\n",
    ">城市：'全国'、 '北京、 '上海'、 '天津'、 '重庆'、 '广州'、'深圳'、 '苏州'、 '南京'、 '杭州'、 '大连'、'成都'、 '武汉'、 '西安'\n",
    ">关键词：不限制\n",
    ">工作经验：'应届生'、 '实习生'、 '1年以内'、 '1-3年'、'3-5年'、 '5-10年'、'10年以上'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "97aaf4fe",
   "metadata": {},
   "outputs": [],
   "source": [
    "headers =  {\n",
    "    'Accept': 'application/json, text/plain, */*',\n",
    "    'Accept-Encoding': 'gzip, deflate, br',\n",
    "    'Accept-Language': 'zh-CN,zh;q=0.9',\n",
    "    'Cache-Control': 'no-cache',\n",
    "    'Connection': 'keep-alive',\n",
    "    'Content-Length': '412',\n",
    "    'Content-Type': 'application/json;charset=UTF-8;',\n",
    "    'Cookie': '__gc_id=c6cb143f1dd942d6bd65b5fc30dd9455; __uuid=1679028387067.72; XSRF-TOKEN=UH8huvwpTv6t6qio3oBLOQ; __tlog=1680236490389.81%7C00000000%7C00000000%7C00000000%7C00000000; acw_tc=2760829b16802364916274153ea3634a30db54784953710df86b64d1b3fc3d; Hm_lvt_a2647413544f5a04f00da7eee0d5e200=1679028387,1679636666,1680236492; __session_seq=5; __uv_seq=5; Hm_lpvt_a2647413544f5a04f00da7eee0d5e200=1680236637',\n",
    "    'Host': 'apic.liepin.com',\n",
    "    'Origin': 'https://www.liepin.com',\n",
    "    'Pragma': 'no-cache',\n",
    "    'Referer': 'https://www.liepin.com/',\n",
    "    'sec-ch-ua': '\"Google Chrome\";v=\"111\", \"Not(A:Brand\";v=\"8\", \"Chromium\";v=\"111\"',\n",
    "    'sec-ch-ua-mobile': '?0',\n",
    "    'sec-ch-ua-platform': '\"macOS\"',\n",
    "    'Sec-Fetch-Dest': 'empty',\n",
    "    'Sec-Fetch-Mode': 'cors',\n",
    "    'Sec-Fetch-Site': 'same-site',\n",
    "    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36',\n",
    "    'X-Client-Type': 'web',\n",
    "    'X-Fscp-Bi-Stat': '{\"location\": \"https://www.liepin.com/zhaopin/?inputFrom=www_index&workYearCode=0&key=%E4%BA%A7%E5%93%81%E7%BB%8F%E7%90%86&scene=input&ckId=htihov8m2frxgy6ywo2wsg2gncnydzlb&dq=\"}',\n",
    "    'X-Fscp-Fe-Version': '',\n",
    "    'X-Fscp-Std-Info': '{\"client_id\": \"40108\"}',\n",
    "    'X-Fscp-Trace-Id': 'ca0f2044-5eea-413c-bc5a-1ebff017261f',\n",
    "    'X-Fscp-Version': '1.1',\n",
    "    'X-Requested-With': 'XMLHttpRequest',\n",
    "    'X-XSRF-TOKEN': 'UH8huvwpTv6t6qio3oBLOQ'\n",
    "}\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "ac4d985d",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "6c14ff01",
   "metadata": {},
   "outputs": [],
   "source": [
    "payload = {\n",
    "    \"data\": {\n",
    "        \"mainSearchPcConditionForm\": {\n",
    "            \"city\": \"410\",\n",
    "            \"dq\": \"410\",\n",
    "            \"pubTime\": \"\",\n",
    "            \"currentPage\": 0,\n",
    "            \"pageSize\": 40,\n",
    "            \"key\": \"产品经理\",\n",
    "            \"suggestTag\": \"\",\n",
    "            \"workYearCode\": \"0\",\n",
    "            \"compId\": \"\",\n",
    "            \"compName\": \"\",\n",
    "            \"compTag\": \"\",\n",
    "            \"industry\": \"\",\n",
    "            \"salary\": \"\",\n",
    "            \"jobKind\": \"\",\n",
    "            \"compScale\": \"\",\n",
    "            \"compKind\": \"\",\n",
    "            \"compStage\": \"\",\n",
    "            \"eduLevel\": \"\"\n",
    "        },\n",
    "        \"passThroughForm\": {\n",
    "            \"scene\": \"input\",\n",
    "            \"skId\": \"\",\n",
    "            \"fkId\": \"\",\n",
    "            \"ckId\": \"h2c8pxojavrmo1w785z7ueih2ybfpux8\",\n",
    "            \"suggest\": None\n",
    "        }\n",
    "    }\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "68084742",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'session' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[15], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m r \u001b[38;5;241m=\u001b[39m session\u001b[38;5;241m.\u001b[39mpost(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mhttps://api-c.liepin.com/api/com.liepin.searchfront4c.pc-search-job\u001b[39m\u001b[38;5;124m'\u001b[39m)\n",
      "\u001b[1;31mNameError\u001b[0m: name 'session' is not defined"
     ]
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "724e407c",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'session' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[11], line 2\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;66;03m# 关于liepin核心参数的详细信息获取（帮助后续分类查询）\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m r \u001b[38;5;241m=\u001b[39m session\u001b[38;5;241m.\u001b[39mpost(\n\u001b[0;32m      3\u001b[0m     url \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mhttps://api-c.liepin.com/api/com.liepin.searchfront4c.pc-search-job-cond-init\u001b[39m\u001b[38;5;124m'\u001b[39m,\n\u001b[0;32m      4\u001b[0m     data \u001b[38;5;241m=\u001b[39m json\u001b[38;5;241m.\u001b[39mdumps(payload),\u001b[38;5;66;03m#POST请求带的参数\u001b[39;00m\n\u001b[0;32m      5\u001b[0m     headers \u001b[38;5;241m=\u001b[39m headers \u001b[38;5;66;03m#模拟真实用户\u001b[39;00m\n\u001b[0;32m      6\u001b[0m )\n\u001b[0;32m      7\u001b[0m condition \u001b[38;5;241m=\u001b[39m r\u001b[38;5;241m.\u001b[39mjson()\n\u001b[0;32m      8\u001b[0m condition\n",
      "\u001b[1;31mNameError\u001b[0m: name 'session' is not defined"
     ]
    }
   ],
   "source": [
    "# 关于liepin核心参数的详细信息获取（帮助后续分类查询）\n",
    "r = session.post(\n",
    "    url = 'https://api-c.liepin.com/api/com.liepin.searchfront4c.pc-search-job-cond-init',\n",
    "    data = json.dumps(payload),#POST请求带的参数\n",
    "    headers = headers #模拟真实用户\n",
    ")\n",
    "condition = r.json()\n",
    "condition"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2bb20438",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
